package com.xxxx.crm.controller;

import com.xxxx.crm.annoation.RequiredPermission;
import com.xxxx.crm.base.BaseController;
import com.xxxx.crm.base.ResultInfo;
import com.xxxx.crm.query.CustomerOrderQuery;
import com.xxxx.crm.service.CustomerOrderService;
import com.xxxx.crm.vo.CusDevPlan;
import com.xxxx.crm.vo.CustomerOrder;
import com.xxxx.crm.vo.SaleChance;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
(。_。)
 */
@RequestMapping("order")
@Controller
public class CustomerOrderController extends BaseController {

    @Resource
    private CustomerOrderService customerOrderService;


    /**
     * 分页多条件查询客户订单列表
     *
     *
(。_。)
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerOrderByParams(CustomerOrderQuery customerOrderQuery) {
        return customerOrderService.queryCustomerOrderByParams(customerOrderQuery);
    }


    /**
     * 进入添加/修改订单信息页面
     */
    @RequestMapping("toAddOrUpdateCustomerOrderPage")
    public String toAddOrUpdateCustomerOrderPage(Model model,Integer cId,Integer id) {
        // 将客户ID设置到请求域中，给计划项页面获取
        model.addAttribute("cId", cId);
        // 通过订单ID查询记录
        CustomerOrder customerOrder = customerOrderService.selectByPrimaryKey(id);
        // 将计划项数据设置到请求域中
        model.addAttribute("customerOrder", customerOrder);
        return "customer/orderAdd_update";
    }

    /**
     * 添加计划项
     *
     *
     (。_。)
     * @param customerOrder
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCustomerOrder(CustomerOrder customerOrder) {
        customerOrderService.addCustomerOrder(customerOrder);
        return success("订单信息添加成功！");
    }

    /**
     * 更新计划项
     *
     *
     (。_。)
     * @param customerOrder
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateCustomerOrder(CustomerOrder customerOrder) {
        customerOrderService.updateCustomerOrder(customerOrder);
        return success("订单信息更新成功！");
    }

    /**
     * 删除计划项
     *
     *
     (。_。)
     * @param id
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteCustomerOrder(Integer id) {
        customerOrderService.deleteCustomerOrder(id);
        return success("订单信息删除成功！");
    }


    /**
     * 支付
     *
     *
     (。_。)
     * @param id
     * @return com.xxxx.crm.base.ResultInfo
     */
    @PostMapping("pay")
    @ResponseBody
    public ResultInfo pay(Integer id) {
        // 调用Service层的删除方法
        customerOrderService.pay(id);
        return success("订单支付成功！");
    }


    /**
     * 打开订单详情的页面
     *
     *
     (。_。)
     * @param
     * @return java.lang.String
     */
    @RequestMapping("toOrderDetailPage")
    public String toOrderDetailPage(Integer orderId, Model model) {

        // 通过订单ID查询对应的订单记录
        Map<String,Object> map = customerOrderService.queryOrderById(orderId);
        // 将数据设置到请求域中
        model.addAttribute("order",map);

        return "customer/customer_order_detail";
    }


}

